import socket

import uvicorn
from pydantic import BaseModel
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()


# 假设PyFlink服务端的地址和端口
FLINK_HOST = 'localhost'
FLINK_PORT = 9999



@app.get("/comment/{item}")
async def process_comment(item):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.connect((FLINK_HOST, FLINK_PORT))
        s.sendall(item.encode('utf-8'))

    return "发送成功"

if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=8000)